﻿@{ ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<form class="layui-form" style="padding-top: 10px;">
    <input style="display:none" id="tbid" value="@ViewBag.tbid">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" name="v" value="2">
            <input type="checkbox" name="BShow" id="BShow" checked="checked" lay-skin="primary" title="已添加的不再显示" value="1" lay-filter="BShow">
        </div>
        <div class="layui-inline">
            @Html.DropDownList("IndexSortID", (IEnumerable<SelectListItem>)ViewBag.IndexSortList, "==所有分类==", new Dictionary<string, object> { })
        </div>
        <div class="layui-inline">
            @Html.DropDownList("IndexDataType", (IEnumerable<SelectListItem>)ViewBag.DtaeTypeList, "==所有类型==", new Dictionary<string, object> { })
        </div>
        <div class="layui-inline">
            <input type="text" name="key" id="key" placeholder="关键字" class="layui-input">
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-primary" id="search"><i class="layui-icon layui-icon-search"></i></button>
            <button type="button" class="layui-btn layui-btn-primary" title="新建指标" id="add_index"><i class="layui-icon layui-icon-add-1"></i></button>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md5">
            <table class="layui-hide" id="lefttable" lay-filter="tableFilter"></table>
        </div>

        <div style="text-align: center; vertical-align: middle; ">
            <div class="layui-col-md2" style="padding-top: 100px; ">
                <button type="button" class="layui-btn" id="addindex">
                    添加&nbsp;<i class=" fa fa-angle-double-right
fa-angle-"></i>
                </button><br /><br />
                <button type="button" class="layui-btn layui-btn-danger" id="delindex"><i class="fa fa-angle-double-left"></i>&nbsp;移除</button>
            </div>
        </div>
        <div class="layui-col-md5">
            <table class="layui-hide" id="righttable" lay-filter="tableFilter"></table>
        </div>
    </div>
</form>

<script>
    layui.use(["table", 'form', "exLayer", "exUtils"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let table = layui.table;

        let $ = layui.$;

        //指标查询
        $("#search").click(function () {
            var ishow = 'n';
            if ($("#BShow").get(0).checked) {
                ishow = 'y';
            }
            LeftTable.reload({
                where: { key: $("#key").val(), sort: $("#IndexSortID").val(), type: $("#IndexDataType").val(), tbid: $("#tbid").val(), show: ishow }
            });
            return false;
        });

        //指标新增
        $("#add_index").click(function () {
            exLayer.open("新建指标", "/SysTable/IndexBasic/Add", '100%', '100%', '0px', '0px', null, null);
        });

        //添加指标
        $("#addindex").click(function () {
            var checkStatus = table.checkStatus('lefttable');
            var ids = [];
            $(checkStatus.data).each(function (i, o) {//o即为表格中一行的数据
                ids.push(o.IndexId);
            });
            if (ids.length < 1) {
                layer.msg('无选中项');
                return false;
            }
            ids = ids.join(",");
            layer.confirm('您确定要添加指标吗？', function (index) {
                exUtils.ajax("/SysTable/TbSetUp/AddTbIndexByStr", "post", { tbid: $("#tbid").val(), si: ids }, true).done(function (response) {
                    exLayer.greenTickMsg(response.message, function () {
                        RightTable.reload({
                            where: { tbid: $("#tbid").val() }
                        });
                        $("#search").click();
                    });

                }).fail(function (error) {
                    console.log(error);
                });

            });

            return false;
        });

        //移除指标
        $("#delindex").click(function () {
            var checkStatus = table.checkStatus('righttable');
            var ids = [];
            $(checkStatus.data).each(function (i, o) {//o即为表格中一行的数据
                ids.push(o.IndexId);
            });
            if (ids.length < 1) {
                layer.msg('无选中项');
                return false;
            }
            ids = ids.join(",");
            layer.confirm('您确定要移除指标吗？', function (index) {
                exUtils.ajax("/SysTable/TbSetUp/RemoveTbIndexByStr", "post", { tbid: $("#tbid").val(), si: ids }, true).done(function (response) {
                    exLayer.greenTickMsg(response.message, function () {
                        RightTable.reload({
                            where: { tbid: $("#tbid").val() }
                        });
                        $("#search").click();
                    });

                }).fail(function (error) {
                    console.log(error);
                });

            });

            return false;
        });

        let LeftTable = table.render({
            elem: "#lefttable",
            url: "/SysTable/IndexBasic/GetIndexListBySearch?key=" + $("#key").val() + "&sort=" + $("#IndexSortID").val() + "&type=" + $("#IndexDataType").val(),
            defaultToolbar: [],
            height: 312,
            method: "post",
            cols: [[
                { type: "checkbox" },
                { type: "numbers", title: "序号" },
                { field: "IndexId", title: "编码", width: 150, sort: true },
                { field: "IndexName", title: "名称", width: 150, sort: true },
                { field: "DataTypeName", title: "类型", sort: true }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        let RightTable = table.render({
            elem: "#righttable",
            url: "/SysTable/TbSetUp/GetTbIndexList?tbid=" + $("#tbid").val(),
            defaultToolbar: [],
            height: 312,
            limits: [100],
            limit: 100,
            page: true,
            method: "post",
            cols: [[
                { type: "checkbox" },
                { field: "IndexId", title: "编码", width: 150, sort: true },
                { field: "IndexName", title: "名称", sort: true },
                { field: "DataTypeName", title: "类型", sort: true }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });
    })
</script>